﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
namespace DAO
{
    public class VanChuyenDAO : DataProvider
    {
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {

            VanChuyenDTO objectDTO = new VanChuyenDTO();
            objectDTO.MaChuyen = int.Parse(dt.Rows[i]["MaChuyen"].ToString());
            objectDTO.MaDatVanChuyen = int.Parse(dt.Rows[i]["MaDatVanChuyen"].ToString());
            objectDTO.TinhTrang = int.Parse(dt.Rows[i]["TinhTrang"].ToString());
            
            return (object)objectDTO;
        }

        public VanChuyenDTO[] GetAll()
        {
            String strSQL = "Select * from VANCHUYEN,DATVANCHUYEN Where VANCHUYEN.MaDatVanChuyen = DATVANCHUYEN.MaDatVanChuyen ";
            DataTable dt = new DataProvider().ExecuteQuery(strSQL);

            VanChuyenDTO[] vanchuyenDTOs = new VanChuyenDTO[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
                vanchuyenDTOs[i] = (VanChuyenDTO)GetDataFromDataRow(dt, i);

            return vanchuyenDTOs;
        }

        public void insert(VanChuyenDTO info)
        {
            string insertCommand = "INSERT VANCHUYEN VALUES(" +
                info.MaChuyen+ ", " +
                info.MaDatVanChuyen + ", " +
                info.TinhTrang + ")";

            ExecuteNonQuery(insertCommand);
        }

        public void update(VanChuyenDTO info)
        {
            string updateCommand = "UPDATE VANCHUYEN " +
                                    "SET MaDatVanChuyen = " + info.MaDatVanChuyen + ", " +
                                    " TinhTrang = " + info.TinhTrang +
                                    " WHERE MaChuyen = " + info.MaChuyen;


            ExecuteNonQuery(updateCommand);
        }

        //public void delete(string maLoaiNV)
        //{
        //    string deleteCommand = "DELETE FROM LOAINHANVIEN WHERE MaLoaiNV = " + maLoaiNV;
        //    ExecuteNonQuery(deleteCommand);
        //}
    }
}
